import com.wr.dao.ResumeDao;
import com.wr.pojo.Resume;
import com.wr.service.ResuteService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.persistence.criteria.*;
import java.util.Optional;

/**
 * @author 王瑞
 * @description:
 * @date 2020/2/23  20:16
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-dao.xml","classpath:applicationContext-service.xml", "classpath:applicationContext-mvc.xml"})
public class Mytest {

    @Autowired
    private ResumeDao resumeDao;

    @Test
    public void test1(){
        Resume resume = new Resume();
        resume.setId(1);

        Example<Resume> of = Example.of(resume);

        Optional<Resume> one = resumeDao.findOne(of);

        System.out.println(one.get());

    }

    @Test
    public void test2(){
        Resume byJpaQl = resumeDao.findByJpaQl(1);

        Resume bySql = resumeDao.findBySql(1);

        System.out.println(byJpaQl);
        System.out.println("===================");
        System.out.println(bySql);
    }

    @Test
    public void test3(){
        Specification<Resume> specification = new Specification<Resume>() {
            @Override
            public Predicate toPredicate(Root<Resume> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {

                Path<Object> name = root.get("name");
                Predicate predicate = criteriaBuilder.equal(name, "张三");
                return predicate;
            }
        };

        Optional<Resume> one = resumeDao.findOne(specification);
        System.out.println(one.get());
    }

    @Autowired
    ResuteService resuteService;
    @Test
    public void text5(){
        Resume byId = resuteService.findById(1);
        System.out.println(byId);
    }
}
